package com.aaa.ssm.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author AUSU
 * @version 1.0
 * 创建时间：2025/3/7 15:29
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AjaxResult implements Serializable {
    private Integer code;
    private String msg;
    private Object data;
    public static AjaxResult success(){
        return new AjaxResult(200,"成功",null);
    }
    public static AjaxResult success(Object data){
        return new AjaxResult(200,"成功", data);
    }
    public static AjaxResult error(){
        return new AjaxResult(400,"失败",null);
    }
    public static AjaxResult error(String msg){
        return new AjaxResult(400,msg,null);
    }

    // 失败的静态方法
    public static AjaxResult defeated(String message) {
        return defeated(-1, message);
    }

    public static AjaxResult defeated(int code, String message) {
        return defeated(code, message, null);
    }

    public static AjaxResult defeated(int code, String message, Object data) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMsg(message);
        result.setData(data);
        return result;
    }
}
